<!--
 * @Author: 赵克强 huohuo625@163.com
 * @Date: 2023-11-06 15:19:02
 * @LastEditors: 赵克强 huohuo625@163.com
 * @LastEditTime: 2024-08-19 10:12:07
 * @FilePath: \hy-ui\src\views\render\form\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE,
-->
<template>
  <el-dialog
    :title="title"
    :visible.sync="open"
    width="80%"
    :before-close="close"
  >
    <div>
      <pagerSearchCondition
        ref="pagerSearchConditionZb"
        :searchJson="zbProps.searchJsonZb"
        :getList="getCrudQueryList"
        :openModal="zbProps.openModal"
        :dictData="zbProps.dictDataZb"
        v-if="zbProps.searchJsonZb"
        :zbDisplayButton="zbProps.zbItemConfig.zbDisplayButton"
      />
      <pagerTable
        ref="pagerTableZb"
        :tableColumns="zbProps.tableColumnsZb"
        :searchJson="zbProps.searchJsonZb"
        :getList="getCrudQueryList"
        :tableData="tableData"
        :openModal="zbProps.openModal"
        :dictData="zbProps.dictDataZb"
        :modelLoading="modelLoading"
         :zbDisplayButton="zbProps.zbItemConfig.zbDisplayButton"
         :zbCount="zbCount"
        v-if="zbProps.searchJsonZb && zbProps.tableColumnsZb"
      />
      <div
        slot="footer"
        class="dialog-footer"
        style="display: flex; justify-content: flex-end; margin-top: 20px"
      >
        <el-button @click="close">取 消</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import pagerSearchCondition from "@/views/render/components/pagerSearchCondition";
import pagerTable from "@/views/render/components/pagerTable.vue";
import operateModal from "@/views/render/components/operateModal.vue";
import { crudQueryList } from "@/api/render/pager.js";
export default {
  name: "zbModel",
  components: {
    pagerSearchCondition,
    pagerTable,
    operateModal,
  },
  props: ["title", "open", "close", "zbProps"],
  data() {
    return {
      tableData: [],
      modelLoading: false,
      zbCount:0
    };
  },

  async mounted() {
    this.getCrudQueryList();
  },

  methods: {
    toHump(name) {
      return name
        .toLocaleLowerCase()
        .replace(/\_(\w)/g, function (all, letter) {
          return letter.toUpperCase();
        });
    },
    async getCrudQueryList() {
      this.modelLoading = true;
      let paramsArr = undefined;
      if (this.zbProps?.zbItemConfig?.cnSm) {
        paramsArr = JSON.parse(this.zbProps.zbItemConfig?.cnSm);
      }

      const params = {
        ...this.$refs.pagerSearchConditionZb?.form,
        ...this.$refs.pagerTableZb?.queryParams,
      };
      console.log(this.zbProps.zbItemConfig);
      if (paramsArr.length) {
        paramsArr.forEach((item) => {
          if (item.in && item.out) {
            let toIn = this.toHump(item.in)
            params[`q__${toIn}`] = this.zbProps.zbRowData?.[item.out];
          }
        });
      }
      const res = await crudQueryList(
        this.zbProps.zbItemConfig?.zbCode,
        params
      );
      if (res.code === 200) {
        this.tableData = res.data;
        this.zbCount = res.data.count
      }
      this.modelLoading = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.pager {
  ::v-deep .el-card {
    // min-height: 88vh !important;
  }
}
</style>